package decorator;

/**
 * GameObject 游戏所有的物体抽象类
 */
abstract class GameObject{
   abstract void plain();
}

/**
 * 地图
 */
class Map extends GameObject{

    @Override
    void plain() {

    }
}

/**
 * 子弹
 */
class Bullet extends GameObject{

    @Override
    void plain() {
        System.out.println("子弹");
    }
}

/**
 * 坦克
 */
class Tank extends GameObject{

    @Override
    void plain() {

    }
}

/**
 * 给所有的物体加边框
 */
class RectDecorator extends GameObject{
    private GameObject gameObject;
    RectDecorator(GameObject gameObject){
        this.gameObject = gameObject;
    }
    @Override
    void plain() {
        System.out.println("给当前物体加边框");
        gameObject.plain();
    }
}


/**
 * 给装饰器在加内容
 */
class TailDecorator extends GameObject{
    private GameObject gameObject;
    TailDecorator(GameObject gameObject){
        this.gameObject = gameObject;
    }
    @Override
    void plain() {
        System.out.println("给所有的装饰器都加");
        gameObject.plain();
    }
}


/**
 * 装饰器模式
 */
public class Decorator {
    public static void main(String[] args) {
        new TailDecorator(
                new RectDecorator(
                        new Bullet()
                )
        ).plain();
    }
}
